package com.letoken.platform.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.admin.service.AdminRoleService;
import com.letoken.platform.pub.annotation.auth.Permission;
import com.letoken.platform.pub.annotation.pub.Trim;
import com.letoken.platform.pub.req.PageData;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.admin.req.config.AddAdminRoleReq;
import com.letoken.platform.repo.admin.req.config.QueryAdminRoleReq;
import com.letoken.platform.repo.admin.req.config.UpdateAdminRoleReq;
import com.letoken.platform.repo.admin.res.user.QueryAdminRoleByIdRes;
import com.letoken.platform.repo.admin.res.user.QueryAdminRoleRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wyl
 * @date 2022/12/13 17:55
 * @Version 1.0
 */
@RestController
@RequestMapping("/role")
@Api(tags = "admin角色相关接口")
public class AdminRoleController {

    @Autowired
    private AdminRoleService adminRoleService;

    @Permission(uri="/role/query",qx = "/admin/roleList")
    @Trim
    @PostMapping("/query")
    @ApiOperation(value = "查询角色列表", notes = "查询角色列表")
    public ApiResponse<PageData<QueryAdminRoleRes>> queryAdminRole(@RequestBody @Validated QueryAdminRoleReq req) {
        return ApiResponse.create(adminRoleService.queryAdminRole(req));
    }

    @Permission(uri="/role/query",qx = "/admin/roleList")
    @Trim
    @PostMapping("/query/{adminRoleId}")
    @ApiOperation(value = "根据id查询角色", notes = "根据id查询角色")
    public ApiResponse<QueryAdminRoleByIdRes> queryAdminRoleById(@PathVariable("adminRoleId") Integer adminRoleId) {
        return ApiResponse.create(adminRoleService.queryAdminRoleById(adminRoleId));
    }

    @Permission(uri="/role/add",qx = "/role/add")
    @Trim
    @PostMapping("/add")
    @ApiOperation(value = "新增角色", notes = "新增角色")
    public ApiResponse addAdminRole(@RequestBody @Validated AddAdminRoleReq req) {
        adminRoleService.addAdminRole(req);
        return ApiResponse.create();
    }

    @Permission(uri="/role/update",qx = "/role/update")
    @Trim
    @PostMapping("/update")
    @ApiOperation(value = "修改角色", notes = "修改角色")
    public ApiResponse updateAdminRole(@RequestBody @Validated UpdateAdminRoleReq req) {
        adminRoleService.updateAdminRole(req);
        return ApiResponse.create();
    }

    @Permission(uri="/role/delete",qx = "/role/delete")
    @Trim
    @PostMapping("/delete/{adminRoleId}")
    @ApiOperation(value = "根据id删除角色", notes = "根据id删除角色")
    public ApiResponse deleteAdminRole(@PathVariable("adminRoleId") Integer adminRoleId) {
        adminRoleService.deleteAdminRole(adminRoleId);
        return ApiResponse.create();
    }
}
